//这是用户登录组件，用于处理用户的登录操作。
<template>
    <el-form :model="form" class="login-form" @submit.native.prevent="handleSubmit">
      <el-form-item label="用户名" :label-width="labelWidth">
        <el-input v-model="form.username" autocomplete="off" />
      </el-form-item>
      <el-form-item label="密码" :label-width="labelWidth">
        <el-input
          v-model="form.password"
          type="password"
          autocomplete="off"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" native-type="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </template>
  
  <script>
  import axios from 'axios';
  
  export default {
    data() {
      return {
        form: {
          username: '',
          password: '',
        },
        labelWidth: '80px',
      };
    },
    methods: {
      async handleSubmit() {
        try {
          const response = await axios.post('/api/login', this.form);
          if (response.data.success) {
            this.$router.push('/');
          } else {
            alert('登录失败');
          }
        } catch (error) {
          console.error('登录请求失败', error);
        }
      },
    },
  };
  </script>
  
  <style scoped>
  .login-form {
    max-width: 300px;
    margin: 0 auto;
    padding: 30px;
  }
  </style>
  